var urlParamObj = $$.util.urlParamToObj();
//展开分类
var toggleCategory = function () {
    $('.category-btn').click(function () {
        var str = 'keyboard_arrow_up';
        if($(this).find('.icon-arrow').text() == str) str = 'keyboard_arrow_down';
        $(this).find('.icon-arrow').text(str).end().next().toggleClass('active');
        $('.category-btn').not(this).find('.icon-arrow').text('keyboard_arrow_down').end().next().removeClass('active');
    });
};
//版块激活
var activateSide = function () {
    var path = location.pathname;
    var pathArray = ['datalist','planlist','setting'];
    for(var i in pathArray){
        if(path.indexOf(pathArray[i]) > -1){
            $('.menu-list [data-path="'+ pathArray[i] +'"]').addClass('active');
            break;
        }
    }
};
//获取分类
var getClassify = function () {
    var paramArray = ['template','hospital','doctor'];
    for(var i = 0,len = paramArray.length;i<len;i++){
        (function (param) {
            new followupPlan().classifyFilter(param,JSON.parse(localStorage.userInfo).userid,function (res,status) {
                res = JSON.parse(res);
                if(res.code == '000'){
                    var resData = JSON.parse(res.data);
                    var len = resData.length;
                    var html = '';
                    var currentUrl = location.href.split('?')[0];
                    if(currentUrl.indexOf('datalist.html') < 0 && currentUrl.indexOf('planlist.html') < 0) currentUrl = '../plan/datalist.html';
                    for(var i = 0;i<len;i++){
                        html += '<a data-id="'+ resData[i].id +'" href="'+ currentUrl+ '?'+ param +'=' + resData[i].id +'">'+ resData[i].name +'</a>';
                    }
                    $('#'+ param +'Classify').html(html);
                    //还原分类点击状态
                    if(urlParamObj[param]){
                        $('.categories-box a[data-id="'+ urlParamObj[param] +'"]').addClass('active').parent().prev().click();
                    }
                }
            });
        })(paramArray[i]);
    }
};
$(function () {
    toggleCategory();
    activateSide();
    getClassify();
});